
// 导入
const express = require('express');
const path = require('path')
// 创建一个express实例，（即创建一个机遇express的web服务）
const app = express();

const mongodb = require('./connect/connect')

//设置跨域访问
app.all('*', function(req, res, next) {
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "X-Requested-With");
	res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
	res.header("Content-Type", "application/json;charset=utf-8");
	next();
});

// 静态资源 (告诉服务器当前项目静态资源位置)
app.use(express.static(path.join(__dirname,'public')))

// post方式提交时，解析body（请求体）数据
// const bodyParser = require('body-parser');
// 获取解析json类型请求体
app.use(express.json());
// 获取解析application/x-www-form-urlencoded类型请求体
app.use(express.urlencoded({extended: false}));

//导入路由模块（绑定路由）
// const router = require('./routes/login_router.js');
const router = require('./routes/login_router.js');
const User_router = require('./routes/userManage.js');
//注册路由并设置命名空间
app.use(router);
app.use('/admin',User_router);



// 指定监听服务的端口
app.listen(8787,()=>{
	console.log('server start...')
})